# Maintainer:  Marty Plummer (The_NetZ) <ntzrmtthihu777 (at) gmail (dot) com>
# Maintainer:  Simon Legner <Simon.Legner@gmail.com>
# Maintainer:  Chris Molozian (novabyte) <chris DOT molozian AT gmail DOT com>
# Maintainer:  Maximilian Salomon <msal.coding@gmail.com>
# Contributor: Sanjuro Makabe (itti) <vuck AT gmx DOT de>
# Contributor: Simón Oroño <simonorono AT protonmail DOT com>
# Contributor: Eon Jeong <administrator@korea.ac.kr>

pkgname=('gradle' 'gradle-doc')
pkgver=6.1.1
pkgrel=1
arch=('any')
url='https://www.gradle.org/'
license=('APACHE')
source=("https://services.gradle.org/distributions/gradle-${pkgver}-all.zip"
        "gradle.sh")
sha256sums=('10065868c78f1207afb3a92176f99a37d753a513dff453abb6b5cceda4058cda'  # gradle-xxx-all.zip
            '0d6699a246bc86c40fb2da3fe73f8e3b228201a8781194d8b303e239d2fa758e') # gradle.sh

package_gradle(){
  pkgdesc="A powerful build system for the JVM"
  # install profile.d script
  install -dm755 "${pkgdir}"/etc/profile.d
  install -m755 "${srcdir}/${pkgname}.sh" "${pkgdir}/etc/profile.d/"
  cd "${srcdir}/${pkgname}-${pkgver}"

  # create the necessary directory structure
  mkdir -p "${pkgdir}/usr/share/java/${pkgname}/bin"
  mkdir -p "${pkgdir}/usr/share/java/${pkgname}/lib/plugins"
  mkdir -p "${pkgdir}/usr/bin"

  # copy across jar files
  install -Dm644 lib/*.jar "${pkgdir}/usr/share/java/${pkgname}/lib" || return 1
  install -Dm644 lib/plugins/*.jar "${pkgdir}/usr/share/java/${pkgname}/lib/plugins" || return 1

  # copy across supporting text documentation and scripts
  install -m644 LICENSE "${pkgdir}/usr/share/java/${pkgname}" || return 1            # license
  install -m644 NOTICE "${pkgdir}/usr/share/java/${pkgname}" || return 1             # license notes
  install -m755 bin/gradle "${pkgdir}/usr/share/java/${pkgname}/bin" || return 1     # UNIX script
  install -m755 bin/gradle.bat "${pkgdir}/usr/share/java/${pkgname}/bin" || return 1 # Windows script
}

package_gradle-doc() {
  pkgdesc="A powerful build system for the JVM (documentation and samples)"
  options=('!strip')
  optdepends=("gradle")
  cd "${srcdir}/gradle-${pkgver}"

  # create the necessary directory structure
  mkdir -p "${pkgdir}/usr/share/java/gradle/docs/"
  mkdir -p "${pkgdir}/usr/share/java/gradle/samples/"

  # copy across documentation
  cp --recursive docs/* "${pkgdir}/usr/share/java/gradle/docs/"
}
